package fem2;

import inf.text.ArrayFormat;
import fem2.analysis.Analysis;
import fem2.analysis.NonlinearStaticAnalysis;
import fem2.enu.EchoLevelType;
import fem2.material.PatchTestVonMises;
import fem2.observer.ResistantGraphicalObserver;

public class ResistantObserverTest {

	public static void main(String[] args) {
		Model model = PatchTestVonMises.createModel(PatchTestVonMises.createMeshQ4(), 0);

		Mesh mesh = model.getMesh();

		double du = 2;
		Constraint c1 = new Constraint(false, false);
		c1.setValue(0, du);
		Constraint c2 = new Constraint(false, true);
		c2.setValue(0, du);

		mesh.setConstraint(c2, MeshUtilities.seekNodesOnSurface(mesh, 1, 0, -1));
		MeshUtilities.seekNode(mesh, 1, 0).setConstraint(c1);

		Analysis an = new NonlinearStaticAnalysis(model, 10);
		an.getStrategy().addObserver(
				new ResistantGraphicalObserver(model, null, MeshUtilities.seekNode(mesh, 0, 1)));
		an.getStrategy().setEchoLevel(EchoLevelType.OUTPUT);
		an.run();

		for (int i = 0; i < 4; i++) {
			double[] uHatLocal = model.getMesh().getNode(i).getUHatLocal();
			System.out.println(ArrayFormat.format(uHatLocal));
		}

		// IVector epsilon = ((StructuralElement)
		// m.getElement(0)).computeTotalStrain(0);
		// IVector sigma = ((StructuralElement) m.getElement(0)).getStress(0);
		// System.out.println("strain = " + epsilon);
		// System.out.println("stress = " + sigma);
	}
}
